// pages/complaint-detail/complaint-detail.js
import api from "../../../utils/request"
Page({
  data: {
    id: "",
    statusClass: "pending",
    detail: {
      id: "1",
      caseNumber: "TS202312010001",
      submitTime: "2023-12-01",
      type: 0,
      description:
        "小区内噪音污染严重，影响正常休息，希望物业能够加强管理。小区内噪音污染严重，影响正常休息，希望物业能够加强管理。",
      status: 1,
      statusText: "已回复",
      houseAddress: "城市花园1栋1单元1层101",
      replyContent:
        "感谢您的反馈，我们已经安排工作人员加强小区内的巡查，并制定了相关的噪音管理规定。如有问题请及时联系我们。",
      replyTime: "2023-12-02",
      evaluationContent: "",
      responderName: "张管家",
    },
  },

  onLoad(options) {
    if (options.id) {
      this.setData({
        id: options.id,
      })
      this.fetchDetail(options.id)
    }
  },

  // 获取详情数据
  fetchDetail(id) {
    wx.showLoading({
      title: "加载中...",
    });
  
    // 模拟API请求
    setTimeout(async () => {
      const result = await api.get(`/property/complaint/${id}`);
      const complaintData = result.data;
      const statusTextMap = {
        0: "待回复",
        1: "已回复",
        2: "已评价",
      };
      complaintData.statusText = statusTextMap[complaintData.status] || "未知状态"; // 添加状态文本
      this.setData({
        detail: complaintData,
        statusClass: this.getStatusClass(complaintData.status),
      });
      wx.hideLoading();
    }, 500);
  },

  // 获取状态样式类
  getStatusClass(status) {
    const statusMap = {
      0: "pending",
      1: "replied",
      2: "evaluated",
    }
    return statusMap[status] || "pending"
  },

  // 评价回复
  onEvaluate() {
    console.log(this.data.id)
    wx.navigateTo({
      url: `/pages/property/complaint-evaluate/complaint-evaluate?id=${this.data.id}`,
    });
  },
})
